//
//  ThreadTableViewCell.m
//  learn-thread
//
//  Created by srxboys on 2021/4/21.
//

#import "ThreadTableViewCell.h"

NSString * const ThreadCellIdentifier = @"ThreadCellIdentifier";

@interface ThreadTableViewCell()
@property (nonatomic, strong) UIView * cellContentView;
@end

@implementation ThreadTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = RX_BOUND_W(self.contentView);
    CGFloat height = RX_BOUND_H(self.contentView);

    CGFloat contentWidth = width - 30;
    CGFloat contentHeight = height - 20;
    _cellContentView.frame = CGRectMake(15, 10, contentWidth, contentHeight);

    CGFloat left = 15;
    CGFloat rowWH = RX_ActureHeight(60);
    CGFloat rowTop = (contentHeight - rowWH) / 2;
    _rowLabel.frame = CGRectMake(left, rowTop, rowWH, rowWH);
    _rowLabel.layer.cornerRadius = rowWH / 2;

    CGFloat contLeft = 15 + left + rowWH;
    CGFloat contWidth = contentWidth - left - contLeft;
    CGFloat titleHeight = 21;
    CGFloat descHeight = 18;
    CGFloat topSpace = 8;
    CGFloat top = (contentHeight - titleHeight - descHeight - topSpace) / 2;
    _titleLabel.frame = CGRectMake(contLeft, top, contWidth, titleHeight);
    top += titleHeight + topSpace;
    _descLabel.frame = CGRectMake(contLeft, top, contWidth, descHeight);
}

- (void)createCell {
    // 很重要，如果超出范围，点击就不会有效
//    self.contentView.backgroundColor = UIColor.redColor;
    self.contentView.clipsToBounds = YES;

    _cellContentView = RXCREATE_ALLOC(UIView);
    _cellContentView.layer.cornerRadius = 4;
    _cellContentView.clipsToBounds = YES;
    _cellContentView.backgroundColor = RXColorHexStr(@"eeeeee");
    [self.contentView addSubview:_cellContentView];

    _rowLabel = RXCREATE_ALLOC(UILabel);
    _rowLabel.backgroundColor = UIColor.grayColor;
    _rowLabel.textColor = UIColor.whiteColor;
    _rowLabel.textAlignment = NSTextAlignmentCenter;
    _rowLabel.font = RX_FontBold(30);
    _rowLabel.clipsToBounds = YES;
    [_cellContentView addSubview:_rowLabel];

    _titleLabel = RXCREATE_ALLOC(UILabel);
    _titleLabel.font = RX_FontBold(16);
    [_cellContentView addSubview:_titleLabel];

    _descLabel = RXCREATE_ALLOC(UILabel);
    _descLabel.font = RX_FontBase(14);
    [_cellContentView addSubview:_descLabel];
}

- (void)btnClick:(UIButton *)btn {
    NSLog(@"btn click");
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
